<?php
    header("Cache-control: private");
    $this->load->view("header2");
?>
<div id="map-canvas"></div>
<div id="all_selected" style="display:none;"><font color="red">全頁選取</font></div>

<?php
  $orderby= !empty($post_data["orderby"])?$post_data["orderby"]:'object_id';
  $sort   = !empty($post_data["sort"])?$post_data["sort"]:'desc';
?>

<input type="hidden"  id="all_page" value="1" >
<input type="hidden"  id="sctime" value="<?= !empty($post_data["sctime"])?strtotime($post_data["sctime"]):''; ?>" >
<input type="hidden"  id="ectime" value="<?= !empty($post_data["ectime"])?strtotime($post_data["ectime"]):''; ?>" >

<input type="hidden"  id="sort" value="<?= !empty($post_data["sort"])?$post_data["sort"]:''; ?>" >


<input type="hidden"  id="object_usage" value="<?= !empty($post_data["object_usage"])?$post_data["object_usage"]:''; ?>" >
<input type="hidden"  id="object_state" value="<?= !empty($post_data["object_state"])?$post_data["object_state"]:''; ?>" >

<input type="hidden"  id="keywords" value="<?= !empty($post_data["keywords"])?$post_data["keywords"]:''; ?>" >
<input type="hidden"  id="bcc" value="<?= !empty($post_data["bcc"])?$post_data["bcc"]:''; ?>" >

<input type="hidden"  id="floor1" value="<?= !empty($post_data["floor1"])?$post_data["floor1"]:''; ?>" >
<input type="hidden"  id="floor2" value="<?= !empty($post_data["floor2"])?$post_data["floor2"]:''; ?>" >


<input type="hidden" name="owner" id="owner" value="<?= !empty($post_data["owner"])?$post_data["owner"]:''; ?>" >
<input type="hidden" name="building_name" id="building_name" value="<?= !empty($post_data["building_name"])?$post_data["building_name"]:''; ?>" >
<input type="hidden" name="case_name" id="case_name" value="<?= !empty($post_data["case_name"])?$post_data["case_name"]:''; ?>" >
<input type="hidden" name="house_building" id="house_building" value="<?=  !empty($post_data["house_building"])?$post_data["house_building"]:''; ?>" >

<input type="hidden"  id="building_area1" value="<?= !empty($post_data["building_area1"])?$post_data["building_area1"]:''; ?>" >
<input type="hidden"  id="building_area2" value="<?= !empty($post_data["building_area2"])?$post_data["building_area2"]:''; ?>" >
<input type="hidden"  id="total1" value="<?= !empty($post_data["total1"])?$post_data["total1"]:''; ?>" >
<input type="hidden"  id="total2" value="<?= !empty($post_data["total2"])?$post_data["total2"]:''; ?>" >
<input type="hidden"  id="broker" value="<?= !empty($post_data["broker"])?$post_data["broker"]:''; ?>" >

<input type="hidden"  id="entrust_start1" value="<?= !empty($post_data["entrust_start1"])?$post_data["entrust_start1"]:''; ?>" >
<input type="hidden"  id="entrust_start2" value="<?= !empty($post_data["entrust_start2"])?$post_data["entrust_start2"]:''; ?>" >
<input type="hidden"  id="object_no" value="<?= !empty($post_data["object_no"])?$post_data["object_no"]:''; ?>" >
<input type="hidden"  id="year_of_construction1" value="<?= !empty($post_data["year_of_construction1"])?$post_data["year_of_construction1"]:''; ?>" >
<input type="hidden"  id="year_of_construction2" value="<?= !empty($post_data["year_of_construction2"])?$post_data["year_of_construction2"]:''; ?>" >

<input type="hidden"  id="latitude1" value="<?= !empty($post_data["latitude1"])?$post_data["latitude1"]:''; ?>" >
<input type="hidden"  id="latitude2" value="<?= !empty($post_data["latitude2"])?$post_data["latitude2"]:''; ?>" >
<input type="hidden"  id="longitude1" value="<?= !empty($post_data["longitude1"])?$post_data["longitude1"]:''; ?>" >
<input type="hidden"  id="longitude2" value="<?= !empty($post_data["longitude2"])?$post_data["longitude2"]:''; ?>" >

<input type="hidden"  id="base_area1" value="<?= !empty($post_data["base_area1"])?$post_data["base_area1"]:''; ?>" >
<input type="hidden"  id="base_area2" value="<?= !empty($post_data["base_area2"])?$post_data["base_area1"]:''; ?>" >

<input type="hidden"  id="area" value="<?= !empty($post_data["area"])?$post_data["area"]:''; ?>" >

<input type="hidden"  id="type_rent" value="<?php echo !empty($post_data["type_rent"])?$post_data["type_rent"]:''; ?>" >
<input type="hidden"  id="type_sale" value="<?php echo !empty($post_data["type_sale"])?$post_data["type_sale"]:''; ?>" >
<input type="hidden"  id="type_help_seal" value="<?php echo !empty($post_data["type_help_seal"])?$post_data["type_help_seal"]:''; ?>" >


<input type="hidden"  id="administrative_area" value="<?=!empty($post_data["administrative_area"])?$post_data["administrative_area"]:'' ?>" >

<?php


$srt_flg=true;
$_object_case_type='';
if(!empty($post_data["object_case_type"])){

  foreach($post_data["object_case_type"] as $_flg => $_val){

    if($srt_flg){
      $srt_flg=false;
      $_object_case_type.=$_val;

    }else{
      $_object_case_type.=",".$_val;
    }

  }

}
?>

<input type="hidden"  id="object_case_type" value="<?=$_object_case_type; ?>" >

<div id="content" style="display:none;">

    <link rel="stylesheet" href="<?= base_url() ?>css/crid_style.css" />
    <link rel="stylesheet" type="text/css" href="<?= base_url() ?>css/flexigrid.pack.css" />
    <script type="text/javascript" src="<?= base_url() ?>js/flexigrid.pack.js"></script>
    <script type="text/javascript" src="<?= base_url() ?>js/flexigrid2.js"></script>

    <table class="flexme4" style="display: none"></table>




    <script type="text/javascript">

        $(".flexme4").flexigrid({
            url: '/obj/queryresult/crid_json',
            dataType: 'json',
            colModel: [
            		{
                    display: '編號',
                    name: 'object_id',
                    width: 100,
                    sortable: true,
                    align: 'left'
                },
               	{
                    display: '建物面積',
                    name: 'building_area',
                    width: 80,
                    sortable: true,
                    align: 'left'
                },
               	{
                    display: '土地面積',
                    name: 'stakeholders_land_area',
                    width: 80,
                    sortable: true,
                    align: 'left'
                },
                {
                    display: '總價',
                    name: 'sale_total',
                    width: 100,
                    sortable: true,
                    align: 'left'
                },
                {
                    display: '地址',
                    name: 'house_building',
                    width: 360,
                    sortable: true,
                    align: 'left'
                }
                ,
                {
                    display: '物件用途',
                    name: 'object_usage',
                    width: 100,
                    sortable: true,
                    align: 'left'
                }
                ,
                {
                    display: '經紀人',
                    name: 'broker',
                    width: 100,
                    sortable: true,
                    align: 'left'
                },
                {
                    display: '建檔日期',
                    name: 'ctime',
                    width: 70,
                    sortable: true,
                    align: 'left'
                },
                {
                    display: '物件編號',
                    name: 'object_no',
                    width: 100,
                    sortable: true,
                    align: 'left'
                }
            ],
            buttons: [
           {
                    name: '配對',
                    bclass: 'pattern',
                    onpress: Example4
                }
                ,
                <?php
            if (check_menu_permissios("object_data_edit")) {
            ?>
                {
                    name: '編輯',
                    bclass: 'edit',
                    onpress: Example4
                }
                ,
            <?php } 
			?>
                {
                    name: '全頁選取',
                    bclass: 'coffee',
                    onpress: Example4
                }
                ,
                {
                    name: 'Excel',
                    bclass: 'coffee',
                    onpress: Example4
                }
                ,
                
            
			
			<?php
            if (check_menu_permissios("object_data_delete")) {
            ?>
                {
                    name: '删除',
                    bclass: 'delete',
                    onpress: Example4
                }
                ,
                <?php
              }
                ?>

                {
                    separator: true
                }
            ],

            sortname: 'object_id',
            sortorder: 'desc',
            usepager: true,
            title: '物件清單',
            checkbox: true, // 是否要多選框
            useRp: true,
            rp: 50,
            width: 'auto',
            height: 'auto',
            procmsg: '資料讀取中，請稍後…',
            nomsg: '找不到符合絛件的資料',
            //margin: 10px 1px 1px -53px
        });
        function Example4(com, grid) {

            if (com == '删除') {
                var empty_str ='';
                var _fg =true;
                  $(".trSelected").each(function() {

                    var str = $(this).children().next().html();
                    var str2 = str.split('</div>');
                    var str = str2[0].split('>');


                    if(_fg){

                      _fg = false;
                      empty_str+= parseInt(str[1]);

                    }else{

                      empty_str+= ","+parseInt(str[1]);

                    }
                });

                $.post('/object/save_object_id', {

                        id : empty_str ,
                        is_del : '0'

                }, function(data) {

                        $.post('/object/del_object_id', {

                        }, function(data) {
                             $(".flexme4").flexReload();
                        });
                });
            }else if (com == '編輯') {



                  $(".trSelected").each(function() {

                    var str = $(this).children().next().html();
                    var str2 = str.split('</div>');
                    var str = str2[0].split('>');

                    var url = '/object/data_edit?id='+parseInt(str[1])+"&type=company";

                    document.location.href = url;

                });



            }
            else if (com == '全頁選取') {
                    var _flag = $("#all_page").val();

                    //alert(_flag);
                    if(_flag=='1'){
                        $("#all_selected").show();
                        $("#all_page").val('2');
                    }else {
                        $("#all_selected").hide();
                        $("#all_page").val('1');
                    }

            }
            else if (com == '配對') {
                var tr_ed = $('.trSelected', grid).length;

                if(tr_ed == 1 ){

                    $(".trSelected").each(function() {

                    var str = $(this).children().next().html();
                    var str2 = str.split('</div>');
                    var str = str2[0].split('>');

                    var url = '/pair/object?id='+parseInt(str[1]);

                    document.location.href = url;

                    });



                }else{
                    alert('一次只能選取一個');
                }
            }
            else if (com == 'Add') {

            }
            else if (com == 'Excel') { 

                var empty_str ='';
                var _fg =true;
                var _flag = $("#all_page").val();



                    if(parseInt(_flag)==2){

                        var url = '/object/all_page_excel?type=company';
                        document.location.href = url;     

                    }else{

                        $(".trSelected").each(function() {

                            var str = $(this).children().next().html();
                            var str2 = str.split('</div>');
                            var str = str2[0].split('>');

                            if(_fg){
                              _fg = false;
                              empty_str+= parseInt(str[1]);
                            }else{
                              empty_str+= ","+parseInt(str[1]);

                            }
                        });

                        $.post('/object/save_object_id', {
                            id : empty_str ,
                            is_del : '0'
                        }, function(data) {
                                  var url = '/object/excel';
                                  document.location.href = url;
                        });
                    }
            /////////////////////////////        
            }



        }


        function save_client(id) {

            $.get('/client/get_save_client_id', {
                id: id
            }, function(data) {

                //alert(data)

            });
        }


        $("document").ready(function() {

            setTimeout('query()', 800);

        });




        function query() {


            var owner = $("#owner").val();
            var building_name = $("#building_name").val();
            var case_name = $("#case_name").val();
            var house_building = $("#house_building").val();

            var total1 = $("#total1").val();
            var total2 = $("#total2").val();
            var building_area1 = $("#building_area1").val();
            var building_area2 = $("#building_area2").val();
            var object_case_type = $("#object_case_type").val();
            var broker = $("#broker").val();

            var entrust_start1 = $("#entrust_start1").val();
            var entrust_start2 = $("#entrust_start2").val();

            var object_no = $("#object_no").val();
            var year_of_construction1 = $("#year_of_construction1").val();
            var year_of_construction2 = $("#year_of_construction2").val();

            var latitude1 = $("#latitude1").val();
            var latitude2 = $("#latitude2").val();
            var longitude1 = $("#longitude1").val();
            var longitude2 = $("#longitude2").val();

            var base_area1 = $("#base_area1").val();
            var base_area2 = $("#base_area2").val();

            var area = $("#area").val();

            var type_rent = $("#type_rent").val();
            var type_sale = $("#type_sale").val();
            var type_help_seal = $("#type_help_seal").val();

            var administrative_area = $("#administrative_area").val();

            var object_usage = $("#object_usage").val();
            var object_state = $("#object_state").val();
            var bcc = $("#bcc").val();

            var floor1 = $("#floor1").val();
            var floor2 = $("#floor2").val();
            var keywords = $("#keywords").val();

            var sort = $("#sort").val();
            var ectime = $("#ectime").val();
            var sctime = $("#sctime").val();


            var _type = 'company';

            $(".flexme4").flexOptions(
                    {newp: 1, params:
                                [
                                    {name: 'owner',
                                        value: owner}
                                    ,
                                    {name: 'sctime',
                                        value: sctime}
                                    ,
                                    {name: 'ectime',
                                        value: ectime}
                                    ,
                                    {name: 'sort',
                                        value: sort}

                                    ,
                                    {name: 'object_state',
                                        value: object_state}
                                    ,
                                    {name: 'keywords',
                                        value: keywords}
                                    ,
                                    {name: 'floor1',
                                        value: floor1}
                                    ,
                                    {name: 'floor2',
                                        value: floor2}
                                    ,
                                    {name: 'bcc',
                                        value: bcc}
                                    ,
                                    {name: 'object_usage',
                                        value: object_usage}
                                    ,
                                    {name: 'type',
                                        value: _type}
                                    ,
                                    {name: 'administrative_area',
                                        value: administrative_area}
                                    ,
                                    {name: 'type_rent',
                                        value: type_rent}
                                    ,
                                    {name: 'type_sale',
                                        value: type_sale}
                                    ,
                                    {name: 'type_help_seal',
                                        value: type_help_seal}
                                    ,
                                    {name: 'v_building_name',
                                        value: building_name}
                                    ,
                                    {name: 'area',
                                        value: area}
                                    ,
                                    {name: 'base_area1',
                                        value: base_area1}
                                    ,
                                    {name: 'base_area2',
                                        value: base_area2}

                                    ,
                                    {name: 'latitude1',
                                        value: latitude1}
                                    ,
                                    {name: 'latitude2',
                                        value: latitude2}
                                    ,
                                    {name: 'longitude1',
                                        value: longitude1}
                                    ,
                                    {name: 'longitude2',
                                        value: longitude2}


                                    ,
                                    {name: 'year_of_construction1',
                                        value: year_of_construction1}
                                    ,
                                    {name: 'year_of_construction2',
                                        value: year_of_construction2}

                                    ,
                                    {name: 'entrust_start1',
                                        value: entrust_start1}
                                    ,
                                    {name: 'entrust_start2',
                                        value: entrust_start2}
                                    ,
                                    {name: 'object_no',
                                        value: object_no}
                                    ,
                                    {name: 'broker',
                                        value: broker}
                                    ,
                                    {name: 'total1',
                                        value: total1}
                                    ,
                                    {name: 'total2',
                                        value: total2}
                                    ,
                                    {name: 'v_case_name',
                                        value: case_name}
                                    ,
                                    {name: 'house_building',
                                        value: house_building}
                                    ,
                                    {name: 'building_area1',
                                        value: building_area1}
                                    ,
                                    {name: 'building_area2',
                                        value: building_area2}
                                    ,
                                    {name: 'object_case_type',
                                        value: object_case_type}


                                ]
                    }).flexReload();
                $("#content").show(); 
        }

    </script>



</div>

<?=
isset($footer) ? $footer : ''?>
